/*
 *  Copyright (C) 2025 ameise <ameise.wang@gmail.com> - All Rights Reserved
 *
 *  This file is part of e3utils.
 *
 *  e3utils is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  e3utils is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with e3utils. If not, see <https://www.gnu.org/licenses/>.
 */

package bytes_buffer

import "io"

type base interface {
	IsCanGrow() bool     // 是否可增长
	GetMaxCapacity() int // 获取可扩展到最大容量
	GetCapacity() int    // 获取总空间大小
	GetDataSize() int    // 获取占用的数据空间大小
	GetEmptySize() int   // 获取空余总空间大小
	IsEmpty() bool       // 是否空数据
}

type PeekReader interface {
	Peek() ([]byte, error)              //查看,但不取出数据
	PeekLen(outLen int) ([]byte, error) //查看指定长度数据
}

type VirtualReader interface {
	VirtualFetchLen(outLen int) ([]byte, error) // 虚读指定长度的数据
	VirtualCommit()                             // 将虚读刷新为实读
	VirtualRecover()                            // 恢复虚读
}

type FetchReader interface {
	Fetch() ([]byte, error) //取出数据,但不做数据拷贝,有数据被覆盖风险
	FetchLen(outLen int) ([]byte, error)
}

type CopyReader interface {
	ReadAll(out []byte) (int, error)      // 读出所有数据,如果传入参数out []byte长度不足,返回错误
	ReadLen(out []byte, outLen int) error // 读取传入参数outLen长度的数据,如果数据不足outLen返回 error
	io.Reader                             // 能读出多少就读出多少
}

type PeekRReader interface {
	Peek() (first, end []byte, err error) //查看,但不取出数据
	PeekLen(outLen int) (first, end []byte, err error)
}

type VirtualRReader interface {
	VirtualFetchLen(outLen int) (first, end []byte, err error) // 虚读指定长度的数据
	VirtualCommit()                                            // 将虚读刷新为实读
	VirtualRecover()                                           // 恢复虚读
}

type FetchRReader interface {
	Fetch() (first, end []byte, err error) //取出数据,但不做数据拷贝,有数据被覆盖风险
	FetchLen(outLen int) (first, end []byte, err error)
}

type Reader interface {
	base
	PeekReader
	VirtualReader
	FetchReader
	CopyReader
}

type RReader interface {
	base
	PeekRReader
	VirtualRReader
	FetchRReader
	CopyReader
}

type Writer interface {
	base
	Clean()
	GrowTo(int) error
	GrowLen(int) (int, error)
	AssignString(string) error
	AssignBytes([]byte) error
	AssignByte(byte) error
	AppendString(string) error // 完整写入,如果 buffer 不足,返回错误
	AppendBytes([]byte) error  // 完整写入,如果 buffer 不足,返回错误
	AppendByte(byte) error
	io.StringWriter //写入可写入长度
	io.Writer       //写入可写入长度
}

type UnsafeWriter interface {
	Writer
	GetTailEmptyBytes() []byte //获取尾部未使用的字节.与AddLen,ResetLen配合使用,用于需要写数据的场景但接口不适用的地方
	AddLen(int)                //向后添加数据长度
	ResetLen(int)              //从当前已读位置开始, 重置数据长度
}
